#include <iostream>
#include <exception>

class Myexception:public std::exception
{
public:
    Myexception(const char* str)
    {
        this->str = str;
    }
    virtual const char *what() const noexcept //当前函数不会抛出异常
    {
        std::cout<<"这是我自己的异常类!\n";
        return str.c_str();
    }
private:
    std::string str;
};

int divide(int a,int b)
{
    if(b == 0)
        throw Myexception("除数为0!");
    return a / b;
}


int main()
{
    try
    {
        divide(1,0);
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }
    

    return 0;
}